package com.jn.erp.web.api.institution.controller;


import com.jn.erp.common.core.page.TableDataInfo;
import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.security.controller.BaseWebAuthController;
import com.jn.erp.web.api.institution.entity.vo.EmployeeVo;
import com.jn.erp.web.api.institution.service.EmployeeService;
import com.jn.erp.web.api.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/institution/staffStudent")
public class StaffStudentController extends BaseWebAuthController {


    @Autowired
    private EmployeeService employeeService;

    @Autowired
    private StudentService studentService;

    //TODO 待删除
    @GetMapping("/listStaff")
    public TableDataInfo studentList(EmployeeVo employeeVo) {
        String orgId = loginDeptAuth();
        employeeVo.setOrgId(Long.valueOf(orgId));
        startPage();
        List<EmployeeVo> list = employeeService.selectEmployeeList(employeeVo);
        ArrayList<Object> list1 = new ArrayList<>();
        for (EmployeeVo sysUsers : list) {
            long id = sysUsers.getId();
            employeeVo.setId(id);
            employeeVo.setOrgId(Long.valueOf(orgId));
            // 已分配在读学员数
            String n = studentService.selCount(employeeVo);
            sysUsers.setNum(n);
            list1.add(sysUsers);
        }
        return getDataTable(list1);
    }

    /**
     * 班级老师列表
     * @param employeeVo
     * @return
     */
    @PostMapping("/peopleList")
    public AjaxResult peopleList(@RequestBody EmployeeVo employeeVo) {
        String orgId = loginDeptAuth();
        employeeVo.setOrgId(Long.valueOf(orgId));
        List<EmployeeVo> list = employeeService.teacherList(employeeVo);
        ArrayList<Object> list1 = new ArrayList<>();
        for (EmployeeVo sysUsers : list) {
            HashMap<Object, Object> map = new HashMap<>();
            map.put("label", sysUsers.getNickName());
            map.put("value", sysUsers.getId());
            // 1 是老师
            map.put("isTeacher", sysUsers.getIsTeach());
            // 1是在职
            map.put("isJob", sysUsers.getIsJob());
            list1.add(map);
        }
        return success(list1);
    }

    /**
     * 学员创建人列表 (包含学员人数)
     * @return
     */
    @GetMapping("/followPeopleList")
    public TableDataInfo followPeopleList(EmployeeVo employeeVo) {
        String orgId = loginDeptAuth();
        employeeVo.setOrgId(Long.valueOf(orgId));
        startPage();
        List<EmployeeVo> list =  employeeService.selectUnifyListStaff(employeeVo);
        return getDataTable(list);
    }
    /**
     * 学管师列表
     * @return
     */
    @GetMapping("/managerList")
    public AjaxResult managerList(EmployeeVo employeeVo) {
        String orgId = loginDeptAuth();
        employeeVo.setOrgId(Long.valueOf(orgId));
        List<EmployeeVo> list = employeeService.managerList(employeeVo);
        return AjaxResult.success(list);
    }
    /**
     * 老师列表
     * @return
     */
    @PostMapping("/teacherList")
    public AjaxResult teacherList(@RequestBody EmployeeVo employeeVo) {
        String orgId = loginDeptAuth();
        employeeVo.setOrgId(Long.valueOf(orgId));
        List<EmployeeVo> list = employeeService.teacherList(employeeVo);
        return AjaxResult.success(list);
    }

    /**
     * 学管师列表(不离职)
     * @return
     */
    @GetMapping("/managerJobList")
    public AjaxResult managerJobList(EmployeeVo employeeVo) {
        String orgId = loginDeptAuth();
        employeeVo.setOrgId(Long.valueOf(orgId));
        List<EmployeeVo> list = employeeService.managerJobList(employeeVo);
        ArrayList<Object> list1 = new ArrayList<>();
        for (EmployeeVo sysUsers : list) {
            long id = sysUsers.getId();
            employeeVo.setId(id);
            employeeVo.setOrgId(Long.valueOf(orgId));
            // 已分配在读学员数
            String n = studentService.selManageCount(employeeVo);
            sysUsers.setNum(n);
            list1.add(sysUsers);
        }
        return AjaxResult.success(list);
    }

    /**
     * 学员创建人列表 (包含学员人数)
     * @return
     */
    @GetMapping("/peopleJobList")
    public TableDataInfo PeopleJobList(EmployeeVo employeeVo) {
        String orgId = loginDeptAuth();
        employeeVo.setOrgId(Long.valueOf(orgId));
        startPage();
        List<EmployeeVo> list =  employeeService.peopleJobList(employeeVo);
        ArrayList<Object> list1 = new ArrayList<>();
        for (EmployeeVo sysUsers : list) {
            long id = sysUsers.getId();
            employeeVo.setId(id);
            employeeVo.setOrgId(Long.valueOf(orgId));
            // 已分配在读学员数
            String n = studentService.selCount(employeeVo);
            sysUsers.setNum(n);
            list1.add(sysUsers);
        }
        return getDataTable(list1);
    }

    /**
     * 业绩归属人
     * @param
     * @return
     */
    @PostMapping("/performanceList")
    public TableDataInfo PerformanceList(@RequestBody EmployeeVo employeeVo) {
        String orgId = loginDeptAuth();
        employeeVo.setOrgId(Long.valueOf(orgId));
        startPage();
        List<EmployeeVo> list =  employeeService.performanceList(employeeVo);
        return getDataTable(list);
    }

}
